package bim.web.controller;

import java.util.List;
import java.util.Map;

import keter.web.util.MediaTypes;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import bim.domain.User;
import bim.service.UserService;
 
@Controller
@RequestMapping("/paper/student")
public class StudentController extends BaseController {

	@Autowired
    UserService ss;
	
	public static class Views {
		private static final String Prefix = "paper/student";
		static final String Index = to_(Prefix) + "index";
		static final String Add = to_(Prefix) + "add";
		static final String Update = to_(Prefix) + "update";
		static final String Delete = to_(Prefix) + "delete";
	}
	
	/**
	 * <p>Method ：login
	 * <p>Description : 处理控制台请求
	 * @return 
	 * @author  gulixing@msn.com
	 * @version 1.0.0
	 */
	@RequestMapping(value = Routes.Index, method = RequestMethod.GET)
	public String index(Model model) {
		return Views.Index;
	}
	
    /**
     * <p>Method ：getMyTopic
     * <p>Description : 获取数据:学生
     *
     * @return
     * @throws Exception 
     * @author  顾力行-gulixing@msn.com
     */
    @RequestMapping(value = Routes.GetAll, method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
    @ResponseBody
    public List<User> get() throws Exception {
        return ss.findByTeacher(getCurrentUser().getId());
    }
    
    /**
     * <p>Method ：removeMyStudents
     * <p>Description : 将指定学生从当前教师的学生列表中移除
     *
     * @param list
     * @param response
     * @return 
     * @author  顾力行-gulixing@msn.com
     */
    @RequestMapping(value=Routes.Delete, method = RequestMethod.GET, consumes = MediaTypes.JSON)
    @ResponseBody
    public Map<String, String> removeMyStudents(@PathVariable Long id) {
    	Map<String, String> ajaxMap = getAjaxMap();
        User s = ss.getDao().findOne(id);
        s.setTeacher(null);
        ss.getDao().save(s);
        return ajaxMap;
    }
	
}